package com.wanggsx.library.base.view;

import androidx.core.content.ContextCompat;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.widget.FrameLayout;

import com.r0adkll.slidr.Slidr;
import com.wanggsx.library.R;
import com.wanggsx.library.util.Utils;
import com.wanggsx.library.util.UtilsBar;

public abstract class BaseBackActivity extends BaseActivity {

    @Override
    public int setRootLayoutId() {
        super.setContentView(R.layout.activity_back);
        Slidr.attach(this);
        FrameLayout drawerContainerView  = findViewById(R.id.drawerContainerView);
        int layoutId = setRootLayout1();
        if (layoutId > 0) {
            LayoutInflater.from(this).inflate(layoutId, drawerContainerView);
        }
        setSupportActionBar((Toolbar) findViewById(R.id.baseBackToolbar));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        UtilsBar.setStatusBarColor(this, ContextCompat.getColor(Utils.getApp(), R.color.lightgray));
        UtilsBar.addMarginTopEqualStatusBarHeight(findViewById(R.id.backRootLayout));
        return 0;
    }

    public abstract int setRootLayout1();

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void setTitle(int titleId) {
        getSupportActionBar().setTitle(getString(titleId));
    }

}
